package finalfrontier;

import java.io.Serializable;

/**Nouvelle version de CarreVie
 * @author Nicolas Roy Boourdages
 */
public class CarreVieElite extends CarreVie implements Serializable {
    
    private static String s = "";
    private static int i = 0;
    private static int ecartX, ecartY;
    
    public CarreVieElite() {
        super();
    }
    
    public CarreVieElite(double energie, double age, double death, String orientation, long seed) {
      super(energie,age,death,orientation,seed);
    }
    
    public static String getRandomDirection(String currentDirection){
    
    s = currentDirection;
    while (s.equals(currentDirection)){
        i = randGen.nextInt(8) + 1;
        
        if (i == 1){
            s = "N";
        }
        else if(i == 2){
            s = "S";
        }
        else if(i == 3){
            s = "E";
        }
        else if(i == 4){
            s = "W";
        }
        else if(i == 5)
        {
          s="NE";
        }
        else if(i == 6)
        {
          s="NW";
        }
        else if(i == 7)
        {
          s="SW";
        }
        else if(i == 8)
        {
          s="SE";
        }
      
    }
    
    return s;
    
  }
    
  public static String getOppositeDirection(int animalX, int animalY, int enemyX, int enemyY){
    
    s = "";
    
    int ecartX = (animalX - enemyX);
    int ecartY = (animalY - enemyY);
    
    if(ecartX == 0 && ecartY == 0)
    {
      s="N"; //default...no tombera jamais la dedans
    }
    else if(ecartX == 0 && ecartY > 0)
    {
      s="N";
    }
    else if(ecartX == 0 && ecartY < 0)
    {
      s="S";
    }
    else if(ecartX < 0 && ecartY == 0)
    {
      s="W";
    }
    else if(ecartX < 0 && ecartY > 0)
    {
      s="NW";
    }
    else if(ecartX < 0 && ecartY < 0)
    {
      s="SW";
    }
    else if(ecartX > 0 && ecartY == 0)
    {
      s="E";
    }
    else if(ecartX > 0 && ecartY > 0)
    {
      s="NE";
    }
    else if(ecartX > 0 && ecartY < 0)
    {
      s="SE";
    }
    else
    {
      s="N"; //default
    }
    
    
    return s;
  }
  
    public static String getTowardsDirection(int animalX, int animalY, int enemyX, int enemyY){
      
      s = "";
      
      int ecartX = (animalX - enemyX);
      int ecartY = (animalY - enemyY);
      
      if(ecartX == 0 && ecartY == 0)
      {
        s="N"; //default...no tombera jamais la dedans
      }
      else if(ecartX == 0 && ecartY > 0)
      {
        s="S";
      }
      else if(ecartX == 0 && ecartY < 0)
      {
        s="N";
      }
      else if(ecartX < 0 && ecartY == 0)
      {
        s="E";
      }
      else if(ecartX < 0 && ecartY > 0)
      {
        s="SE";
      }
      else if(ecartX < 0 && ecartY < 0)
      {
        s="NE";
      }
      else if(ecartX > 0 && ecartY == 0)
      {
        s="W";
      }
      else if(ecartX > 0 && ecartY > 0)
      {
        s="SW";
      }
      else if(ecartX > 0 && ecartY < 0)
      {
        s="NW";
      }
      else
      {
        s="N"; //default
      }
      
      
      return s;
    }
  
  public static int getDistance(int animalX, int animalY, int enemyX, int enemyY){
      ecartX = Math.abs(animalX - enemyX);
      ecartY = Math.abs(animalY - enemyY);
      
      return (int)Math.floor(ecartX + ecartY / 2);
  }

}
